package edu.zqu.course.framework.activiti;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;

import java.util.List;

/**
 * @Author 郭泽鹏
 * @Date 2020/6/21 15:00
 * @Description: 任务完成
 * @Version 1.0
 */

public class ActivitiCompleteTask {
    public static void main(String[] args) {
        /**
         * 1.得到ProcessEngine对象
         */
        ProcessEngineConfiguration configuration = ProcessEngineConfiguration
                .createProcessEngineConfigurationFromResource("activiti/activiti.cfg.xml","processEngineConfiguration");
        ProcessEngine processEngine = configuration.buildProcessEngine();
        /**
         * 2.得到TaskService对象
         */
        TaskService taskService = processEngine.getTaskService();
        /**
         * 3.查询当前用户的任务
         */
        List<Task> taskList = taskService.createTaskQuery()
                .processDefinitionKey("holiday")
                .taskAssignee("zhangsan")
                .list();
        /**
         * 4.处理任务,结合当前用户任务列表的查询操作的话,任务ID:task.getId()
         */
        taskList.forEach((item)->{
            taskService.complete(item.getId());
        });
    }
}
